﻿// See https://aka.ms/new-console-template for more information



//调用JwtSecurityTokenHandler类对JWT令牌进行解码
//串改了jwttoken后报异常:Microsoft.IdentityModel.Tokens.SecurityTokenInvalidSignatureException:
//“IDX10508: Signature validation failed. Signature is improperly formatted.”

using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
string jwt = Console.ReadLine()!;
string secKey = "fasdfad&9045dafz222#fadpio@0232";
JwtSecurityTokenHandler tokenHandler = new();
TokenValidationParameters valParam = new();
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secKey));
valParam.IssuerSigningKey = securityKey;
valParam.ValidateIssuer = false;
valParam.ValidateAudience = false;
ClaimsPrincipal claimsPrincipal = tokenHandler.ValidateToken(jwt,
		valParam, out SecurityToken secToken);
foreach (var claim in claimsPrincipal.Claims)
{ 
	Console.WriteLine($"{claim.Type}={claim.Value}");
}

